﻿
using Setme.Domain.Model.Impl;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace Setme.Domain.Model
{
    public class Employee : AggregateRoot
    {
        public Employee()
        {
            this.Role = new HashSet<Role>();
        }

        [Display(Name = "用户名")]
        [Required(ErrorMessage = "{0}不能为空.")]
        [MinLength(6, ErrorMessage = "{0}必须大于{1}."), MaxLength(18, ErrorMessage = "{0}必须小于{1}.")]
        public string UserName { get; set; }

        [Display(Name = "密码")]
        [Required(ErrorMessage = "{0}不能为空.")]
        [MinLength(6, ErrorMessage = "{0}必须大于{1}."), MaxLength(18, ErrorMessage = "{0}必须小于{1}.")]
        public string PassWord { get; set; }

        [Display(Name = "真实姓名")]
        [Required(ErrorMessage = "{0}不能为空.")]
        [MinLength(2, ErrorMessage = "{0}必须大于{1}."), MaxLength(6, ErrorMessage = "{0}必须小于{1}.")]
        public string RealName { get; set; }

        [Display(Name = "性别")]
        [Required(ErrorMessage = "{0}不能为空.")]
        public EnumStatus.SexStatus Sex { get; set; }

        [Display(Name = "手机号码")]
        [Phone(ErrorMessage = "{0}格式不正确.")]
        public string Phone { get; set; }

        [Display(Name = "座机")]
        public string Tel { get; set; }

        [Display(Name = "电子邮箱")]
        [Required(ErrorMessage = "{0}不能为空.")]
        [EmailAddress(ErrorMessage = "{0}格式不正确.")]
        public string Email { get; set; }

        [Display(Name = "是否启动")]
        [Required(ErrorMessage = "{0}不能为空.")]
        public EnumStatus.OpenStatus Open { get; set; }

        public virtual ICollection<Role> Role { get; set; }

        public static Employee CreateEmployee(string _UserName, string _PassWord, string _RealName,
                                              EnumStatus.SexStatus _Sex, string _Phone, string _Tel,
                                              string _Email, EnumStatus.OpenStatus _Open)
        {
            Employee employee = new Employee();
            employee.UserName = _UserName;
            employee.PassWord = _PassWord;
            employee.RealName = _RealName;
            employee.Sex = _Sex;
            employee.Phone = _Phone;
            employee.Tel = _Tel;
            employee.Email = _Email;
            employee.Open = _Open;
            return employee;
        }

        public void ReSwitch()
        {
            if (this.Open == EnumStatus.OpenStatus.On)
                this.Open = EnumStatus.OpenStatus.Off;
            else
                this.Open = EnumStatus.OpenStatus.On;
        }

        public void RePassword()
        {
            this.PassWord = "000000";
        }
    }
}
